import { createRouter,createWebHistory } from 'vue-router'
//创建路由规则
const routes = [
    { 
        path:'/',
        name: 'main',
        redirect:'/home',
    },
    { 
        path:'/home',
        name: 'home',
        component: () => import("../views/home"),
        meta: {
            title:"积分商城"
        }
    },
    { 
        path:'/mine',
        name: 'mine',
        component: () => import("../views/mine"),
        meta: {
            title:"个人中心"
        }
    },
    { 
        path:'/exchangeRecord',
        name: 'exchangeRecord',
        component: () => import("../views/exchangeRecord"),
        meta: {
            title:"兑换记录"
        }
    },
    { 
        path:'/pointsRecord',
        name: 'pointsRecord',
        component: () => import("../views/pointsRecord"),
        meta: {
            title:"积分记录"
        }
    },
    { 
        path:'/order',
        name: 'order',
        component: () => import("../views/order"),
        meta: {
            title:"我的订单"
        }
    },
    { 
        path:'/address',
        name: 'address',
        component: () => import("../views/address"),
        meta: {
            title:"收货地址"
        }
    },
    { 
        path:'/login',
        name: 'login',
        component: () => import("../views/login"),
        meta: {
            title:"登录"
        }
    },
    { 
        path:'/edit',
        name: 'edit',
        component: () => import("../views/edit"),
        meta: {
            title:"编辑地址"
        }
    },
    { 
        path:'/register',
        name: 'register',
        component: () => import("../views/register"),
        meta: {
            title:"注册"
        }
    },
    { 
        path:'/detail',
        name: 'detail',
        component: () => import("../views/detail"),
        meta: {
            title:"商品详情"
        }
    },
    { 
        path:'/confirmOrder',
        name: 'confirmOrder',
        component: () => import("../views/confirmOrder"),
        meta: {
            title:"订单确认"
        }
    },
    { 
        path:'/orderSuccess',
        name: 'orderSuccess',
        component: () => import("../views/orderSuccess"),
        meta: {
            title:"下单成功"
        }
    }
];

//创建路由实例
const router = createRouter({
    history:createWebHistory(),
    routes,
});
router.beforeEach((to,from,next)=>{
    if(to.meta.title){
        document.title = to.meta.title;
    }
    next();
})
export default router;
//创建登录组件
//指定出口
// import { createRouter, createWebHashHistory } from "vue-router"

// const home = () => import("../home")
// const login = () => import("../login")

// const routes = [
//   { path: "/", redirect: "/home" },
//   {
//     path: "/home",
//     name: "home",
//     component: home
//   },
//   {
//     path: "/login",
//     name: "login",
//     component: login
//   }
// ]

// export const router = createRouter({
//   history: createWebHashHistory(),
//   routes: routes
// })